﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using NUnit.Framework;
using Savage.DotNetLibrary.ImageLibrary;

namespace Savage.DotNetLibrary.TestDotNetLibrary.ImageLibraryTests
{
    [TestFixture]
    public class TestImage
    {
        [Test]
        public void TestCreateThumbnailBitmap()
        {
            ImageUtility iu = new ImageUtility("Samples/test1.jpg");
            Bitmap tn = iu.CreateThumbnail(250, 250);

            Assert.IsTrue(tn.Width == 250 || tn.Height == 250, "Thumbnail did not scale to 250 correctly.");

            //Tidy up
            tn.Dispose();
        }

        [Test]
        public void TestCreateThumbnailFile()
        {
            string tnFileName = "test1_tn.jpg";
            ImageUtility iu = new ImageUtility("Samples/test1.jpg");
            iu.CreateThumbnail(tnFileName, 250, 250);

            Assert.IsTrue(System.IO.File.Exists(tnFileName));

            Bitmap tn = new Bitmap(tnFileName);
            Assert.IsTrue(tn.Width == 250 || tn.Height == 250, "Thumbnail did not scale to 250 correctly.");

            //Tidy up
            tn.Dispose();
            System.IO.File.Delete(tnFileName);
        }

        [Test]
        public void TestCreateThumbnailFileInDirectory()
        {
            string directory = @"tmp\" + Guid.NewGuid().ToString();
            string tnFileName = directory + @"\" + "test1_tn.jpg";

            ImageUtility iu = new ImageUtility("Samples/test1.jpg");
            iu.CreateThumbnail(tnFileName, 250, 250);

            Assert.IsTrue(System.IO.File.Exists(tnFileName));

            Bitmap tn = new Bitmap(tnFileName);
            Assert.IsTrue(tn.Width == 250 || tn.Height == 250, "Thumbnail did not scale to 250 correctly.");
            
            //Tidy up
            tn.Dispose();
            System.IO.File.Delete(tnFileName);
            System.IO.Directory.Delete(directory);
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestCreateThumbnailToFileSourceFilePathArgumentNull()
        {
            ImageUtility iu = new ImageUtility("Samples/test1.jpg");
            iu.CreateThumbnail(null, 680, 480, System.Drawing.Drawing2D.InterpolationMode.Default);
        }

        [Test]
        public void TestThumbnailCallback()
        {
            Assert.AreEqual(false, ImageUtility.ThumbnailCallback());
        }
    }
}
